﻿using System;
using System.Text;

namespace Assignment4
{
    class Program
    {
        static void Main()
        {
            bool doTransaction = true;
            double startTotal = 0;
            double runningTotal = 0;
            double withdrawAmount = 0;
            int deposits = 0;
            double depositAmount = 0;
            int withdrawls = 0;
            double endTotal = 0;

            Console.Write("Please enter the starting balance:  ");
            startTotal = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine();

            Console.WriteLine("What action would you like to perform?");
            Console.WriteLine("Please enter the letter C, D or Q");
            Console.WriteLine("  ->  D - Deposit Money ");
            Console.WriteLine("  ->  C - Withdraw Money ");
            Console.WriteLine("  ->  Q - Quit");
            Console.WriteLine();

            runningTotal = startTotal;

            while (doTransaction)
            {
                Console.WriteLine("Please select an action.");
                Console.WriteLine();
                string action = (Console.ReadLine());
                Console.WriteLine();
                switch (action.ToLower())
                {
                    case "d":
                        {
                            Console.Write("How much would you like to Deposit?: ");
                            depositAmount = Convert.ToDouble(Console.ReadLine());
                            if (depositAmount != 0)
                            {
                                runningTotal += depositAmount;
                                deposits += 1;
                                Console.WriteLine("The current total is:  $ {0:N2}", runningTotal);
                                if (runningTotal < 0)
                                {
                                    Console.WriteLine("WARNING - Your Current Total is negative: $ {0:N2}!!", runningTotal);
                                    Console.WriteLine();
                                }
                            }
                            Console.WriteLine();
                            Console.WriteLine("What action would you like to perform? ");
                            Console.WriteLine();
                            Console.WriteLine("Please enter the letter C, D or Q");
                            Console.WriteLine("  ->  D - Deposit Money ");
                            Console.WriteLine("  ->  C - Withdraw Money ");
                            Console.WriteLine("  ->  Q - Quit");
                            Console.WriteLine();
                        }
                        break;

                    case ("c"):
                        {
                            Console.Write("How much would you like to Withdraw? ");
                            withdrawAmount = Convert.ToDouble(Console.ReadLine());
                            if (withdrawAmount != 0)
                            {
                                runningTotal -= withdrawAmount;
                                withdrawls += 1;
                                Console.WriteLine("The current total is:  $ {0:N2}", runningTotal);
                                if (runningTotal < 0)
                                {
                                    Console.WriteLine("WARNING - Your Current Total is negative: $ {0:N2}!!", runningTotal);
                                    Console.WriteLine();
                                }
                            }
                            Console.WriteLine();
                            Console.WriteLine("What action would you like to perform?");
                            Console.WriteLine();
                            Console.WriteLine("Please enter the letter C, D or Q");
                            Console.WriteLine("  ->  D - Deposit Money ");
                            Console.WriteLine("  ->  C - Withdraw Money ");
                            Console.WriteLine("  ->  Q - Quit");
                            Console.WriteLine();
                        }
                        break;

                    case "q":
                        {
                            Console.WriteLine("Are you sure you want to quit?: Y or N");
                            Console.WriteLine();
                            string quit = (Console.ReadLine()).ToUpper();
                            if (quit == "Y")
                            {
                                doTransaction = false;
                            }
                            else doTransaction = true;
                        }
                        break;

                    default:
                        Console.WriteLine("Please Enter a valid action: D C or Q");
                        break;
                }
            }


            endTotal = runningTotal;
            Console.WriteLine();
            Console.WriteLine("The initial amount was:  $ {0:N2}", startTotal);
            Console.WriteLine("The final amount was:    $ {0:N2}", endTotal);
            Console.WriteLine();
            Console.WriteLine("Number of Deposits:        {0}", deposits);
            Console.WriteLine("Number of Cheques:         {0}", withdrawls);
            Console.WriteLine();
            Console.WriteLine("Nothing left to do, Goodbye");
            Console.ReadKey();
        }
    }
}